

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <!-- 头部操作栏 -->
            <form class="layui-form lay-header">
                <div class="toolbar">
                    <div class="layui-form-item lay-query-content">
                        <div class="lay-query-box">
                            <div class="query-lt">
                                <div class="layui-inline">
                                    <a class="layui-btn icon-btn" lay-filter="add" id="addSetting" lay-submit>添加</a>
<!--                                    <div class="layui-form-item">-->
<!--                                        <label class="layui-form-label">企业名称</label>-->
<!--                                        <div class="layui-input-inline">-->
<!--                                            <select lay-filter="enterpriseId" id="enterpriseId" name="enterpriseId">-->
<!--                                                <option value="">请选择企业</option>-->
<!--                                            </select>-->
<!--                                        </div>-->
<!--                                        &emsp13;-->
<!--                                        <button lay-filter="formSearch" class="layui-btn icon-btn color-orange" lay-submit-->
<!--                                                type="button">查询-->
<!--                                        </button>-->
<!--                                    </div>-->
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </form>
            <!-- 表格 -->
            <table class="layui-table" id="sysSettingTable" lay-filter="sysSettingTable"></table>
        </div>
    </div>
</div>

<!--列表按钮-->
<script type="text/html" id="isDeletedTable">
    <input type="checkbox" lay-filter="ckState" lay-skin="switch" lay-text="开启|停用"
           value="{{d.id}}" {{d.isDeleted==0?'checked':''}}/>
</script>
<!--列表图片-->
<script type="text/html" id="picture">
    <div><img src="{{d.codeUrl}}" style="height: 24px; cursor: pointer" onclick="previewImg(this)"></div>
</script>
<script type="text/html" id="logoPic">
    <div><img src="{{d.logo}}" style="height: 24px; cursor: pointer" onclick="previewImg(this)"></div>
</script>
<!--详情列表图片-->
<script type="text/html" id="advertPicture">
    <div><img src="{{d.advertUrl}}" style="height: 24px; cursor: pointer" onclick="previewImg(this)"></div>
</script>
<!-- 表格操作列 -->
<script type="text/html" id="sysSettingTableBar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">编辑</a>
    <!--    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>-->
</script>

<!-- 详情表格操作列 -->
<script type="text/html" id="sysSettingTableDetailBar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="editDetail">编辑</a>

    <!--    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>-->
</script>

<!-- 表单弹窗 -->
<script type="text/html" id="sysSettingForm">

    <!-- 表格 -->
    <table class="layui-table" id="sysSettingTable1" lay-filter="sysSettingTable1"></table>

    <a class="layui-btn icon-btn" lay-filter="add" id="addAdvert" lay-submit style="margin-left: 20px">添加广告</a>
    <!-- 主表数据   -->
    <form class="layui-form" name="addUserForm">
        <div class="layui-form-item">
            <label class="layui-form-label w-auto"><span class="allSpan">*</span>刀柜客服邮箱</label>
            <div class="layui-input-inline">
                <input name="email" id="email" type="text" class="layui-input" lay-verify="required" required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label w-auto">&emsp;<span class="allSpan">*</span>客服二维码</label>
            <div class="layui-input-block">
                <div id="headImg" class="companyFormPhotos"></div>
                <div id="btn" class="layui-btn" style="float: left;background-color: #009E94;color: white" ><i class="layui-icon">+</i>上传二维码
                </div>
                <input name="codeUrl" id="codeUrl" type="hidden" class="layui-input" lay-verify=""/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label w-auto">&emsp;<span class="allSpan">*</span>logo</label>
            <div class="layui-input-block">
                <div id="logoImg" class="companyFormPhotos"></div>
                <div id="logoBtn" class="layui-btn" style="float: left;background-color: #009E94;color: white" ><i class="layui-icon">+</i>上传logo
                </div>
                <input name="logo" id="logoUrl" type="hidden" class="layui-input" lay-verify=""/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label w-auto"><span class="allSpan">*</span>刀柜客服电话</label>
            <div class="layui-input-inline">
                <input name="mobile" type="text" id="mobile" class="layui-input" lay-verify="required" required/>
            </div>
        </div>
        <div class="layui-form-item" style="margin-left: 40px">
            <label class="layui-form-label w-auto"><span class="allSpan">*</span>广告语</label>
            <div class="layui-input-inline">
                <input name="advertName" id="advertName" type="text" class="layui-input" lay-verify="required" required/>
            </div>
        </div>

        <input name="id" id="settingId" type="hidden" class="layui-input"  lay-verify="" >

        <div class="layui-form-item">
            <div class="layui-input-block">
                &nbsp;&nbsp;<button class="layui-btn" lay-submit lay-filter="submitSys">提交</button>
            </div>
        </div>
    </form>
</script>

<!-- 添加页面-->
<script type="text/html" id="addSettingForm">
        <div class="layui-fluid addPurchaseOrder">
            <form lay-filter="storageWorkAddForm" class="layui-form model-form"
                  style="padding: 5px 20px 0;height: calc(100% - 5px);overflow: hidden;">
                <div class="open-details-box" style="height: calc(100% - 55px);overflow-y: auto;">
                    <div class="layui-form-item">

                        <div class="layui-inline">
                            <label class="layui-form-label w-auto"><span class="allSpan">*</span>柜子客服邮箱</label>
                            <div class="layui-input-inline">
                                <input name="email" id="addEmail" type="text" class="layui-input"  />
                            </div>
                        </div>
<!--                        <div class="layui-inline">-->
<!--                            <label class="layui-form-label">企业名称</label>-->
<!--                            <div class="layui-input-inline">-->
<!--                                <select lay-filter="enterpriseId" id="addEnterpriseId" name="enterpriseId">-->
<!--                                    <option value="">请选择企业</option>-->
<!--                                </select>-->
<!--                            </div>-->
<!--                        </div>-->

                        <div class="layui-inline">
                            <label class="layui-form-label w-auto"><span class="allSpan">*</span>刀柜客服电话</label>
                            <div class="layui-input-inline">
                                <input name="mobile" type="text" id="addMobile" class="layui-input" />
                            </div>
                        </div>
                        <div class="layui-inline" style="margin-left: 40px">
                            <label class="layui-form-label w-auto"><span class="allSpan">*</span>广告语</label>
                            <div class="layui-input-inline">
                                <input name="advertName" id="addAdvertName" type="text" class="layui-input" />
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label w-auto">&emsp;<span class="allSpan">*</span>客服二维码</label>
                            <div class="layui-inline">
                                <div id="addHeadImg" class="companyFormPhotos"></div>
                                <div id="addBtn" class="layui-btn" style="float: left;background-color: #009E94;color: white" ><i class="layui-icon">+</i>上传二维码
                                </div>
                                <input name="codeUrl" id="addCodeUrl" type="hidden" class="layui-input" lay-verify=""/>
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label w-auto">&emsp;<span class="allSpan">*</span>logo</label>
                            <div class="layui-inline">
                                <div id="addLogoImg" class="companyFormPhotos"></div>
                                <div id="addLogoBtn" class="layui-btn" style="float: left;background-color: #009E94;color: white" ><i class="layui-icon">+</i>上传logo
                                </div>
                                <input name="logo" id="addLogoUrl" type="hidden" class="layui-input" lay-verify=""/>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <a class="layui-btn icon-btn" lay-filter="addAdvertBtn" id="addAdvertBtn" lay-submit>添加广告</a>
                        </div>
                    <!-- 表格 -->
                        <table class="layui-table" id="addSettingTable" lay-filter="addSettingTable"></table>
                </div>
                </div>
                <div class="layui-form-item text-right">
                    <a class="layui-btn" lay-filter="addSettingSubmit" id="addSettingSubmit" lay-submit>提交</a>
                    <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
                </div>
            </form>
        </div>
</script>

<script type="text/html" id="sysSettingDetailForm">
    <form lay-filter="settingForm" class="layui-form model-form">
            <input name="id" type="hidden"/>
            <div class="layui-form-item">
                <label class="layui-form-label">广告图名称</label>
                <div class="layui-input-inline">
                    <input name="name" id="name" placeholder="" type="text" class="layui-input" lay-verify="required"
                           required/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">广告图片</label>
                <div class="layui-input-block">
                    <div id="headerImg" class="companyFormPhotos"></div>
                    <div id="devicePicBtn" class="layui-btn" style="float: left;"><i class="layui-icon">&#xe681;</i>上传图片
                    </div>
                    <input name="advertUrl" id="advertUrl" type="hidden" class="layui-input" lay-verify=""/>

                </div>
            </div>

        <div class="layui-form-item">
            <label class="layui-form-label">视频</label>
            <div class="layui-input-block">
                <div id="headerVideo" class="companyFormPhotos"></div>
                <div id="deviceVideoBtn" class="layui-btn" style="float: left;"><i class="layui-icon">&#xe681;</i>上传视频
                </div>
                <input name="advertVideo" id="advertVideo" type="hidden" class="layui-input" lay-verify=""/>

            </div>
        </div>
            <div class="layui-form-item">
                <label class="layui-form-label">链接地址</label>
                <div class="layui-input-inline">
                    <input name="advertLink" id="advertLink" type="text" class="layui-input" lay-verify="required"
                           required/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">是否启用</label>
                <div class="layui-input-inline">
                    <select name="isDeleted" lay-verify="required">
                        <option value="0">显示</option>
                        <option value="1">不显示</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">备注</label>
                <div class="layui-input-inline">
                    <input name="remark" id="remark" placeholder="" type="text" class="layui-input" lay-verify="required"
                           required/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">排序</label>
                <div class="layui-input-inline">
                    <input name="sortNumber" id="sortNumber" placeholder="" type="text" class="layui-input"
                           lay-verify="required" required/>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="settingFormDetailSubmit">提交</button>
                </div>
            </div>
        </form>
</script>

<!-- js部分 -->
<script>
    layui.use(['layer', 'form', 'table', 'admin', 'upload'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var admin = layui.admin;
        var upload = layui.upload;
        var settingList = []; //柜子系统设置
        var advertList = []; //柜子系统设置_广告设置
        var advertin = {}; //柜子系统设置_广告设置
        var ids;
        var advert = {};
        var addAdvertList = []; // 添加的详情数据

        var sysSettingDetailTable1 = layui.table.cache["sysSettingDetailTable1"];


        // 工具条点击事件
        table.on('tool(sysSettingTable)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') { // 详情表格数据
                console.log(data);

                showEditModel(data);

            } else if (obj.event === 'del') { // 删除
                doDelete(obj);
            }
        });

        // 工具条点击事件
        table.on('tool(sysSettingTable1)', function (obj) {
            var data = obj.data;
            if (obj.event === 'editDetail') { // 详情表格数据
                console.log(data);
                showEditDetailModel(data);
            }
        });


        var insTb = table.render({
            elem: '#sysSettingTable',
            url: config.base + 'enterprisecab/cabinet/admin/startSetting/list',
            cellMinWidth: 100,
             // data: settingList,
            cols: [[

                  {type: 'numbers'}
                , {field: 'enterpriseName', sort: false, title: '企业名称'}
                , {field: 'email', sort: false, title: '客服邮箱'}
                , {field: 'codeUrl', sort: false, title: '客服二维码图片地址', templet: '#picture'}
                , {field: 'logo', sort: false, title: 'logo', templet: '#logoPic'}
                , {field: 'mobile', sort: false, title: '客服电话'}
                // , {field: 'isDeleted', templet: '#isDeletedTable', title: '是否启用', unresize: true}
                , {field: 'createTime', sort: false, title: '添加时间'}
                , {align: 'center', toolbar: '#sysSettingTableBar', title: '操作', width: 200}
            ]],
        })

        ;


        // //加载代理商列表
        // admin.reqSync('platform/company/admin/company/list', {limit: 99999}, function (res) {
        //
        //     loadSelectHtml(res.data, "请选择企业", "enterpriseId", "name");
        //     // 第二步 进行数据配对的选择
        //     // 下拉框回显
        //     var select = 'dd[lay-value=' + advertin.enterpriseId + ']';
        //     var changeselect = $('#enterpriseId').siblings("div.layui-form-select").find('dl').find(select).click();
        //     form.render("select");
        // }, 'get', false);


        // 修改状态
        form.on('switch(ckState)', function (obj) {
            layer.load(2);
            admin.req('enterprisecab/cabinet/admin/sysSetting/upIsDelete', {
                id: obj.elem.value,
                isDeleted: obj.elem.checked ? 0 : 1
            }, function (data) {
                layer.closeAll('loading');
                if (data.code == 200) {
                    layer.msg(data.msg, {icon: 1});
                } else {
                    layer.msg(data.msg, {icon: 2});
                    $(obj.elem).prop('checked', !obj.elem.checked);
                    form.render('checkbox');
                }
            }, 'PUT');
        });


        // 显示编辑弹窗
        function showEditModel(data) {
            admin.open({
                type: 1,
                area: ['1180px', '800px'],
                offset: '65px',
                title: '柜子面板启动画面',
                content: $('#sysSettingForm').html(),
                success: function () {
                    var insTb = table.render({

                        elem: '#sysSettingTable1',
                        url: config.base + 'enterprisecab/cabinet/admin/startSetting/getAdvertDetail?id='+data.id,
                        cellMinWidth: 100,
                        // data: advertList,
                        cols: [[
                            {type: 'numbers'}
                            , {field: 'name', sort: false, title: '广告名称'}
                            , {field: 'advertUrl', sort: false, title: '广告图片',templet: '#advertPicture'}
                            , {field: 'advertLink', sort: false, title: '广告链接'}
                            , {field: 'advertVideo', sort: false, title: '视频'}
                            ,{field: 'isDeleted', templet: '#isDeletedTable', title: '是否启用', unresize: true}
                            , {field: 'remark', sort: false, title: '备注'}
                            , {field: 'createTime', sort: false, title: '添加时间'}
                            , {field: 'sortNumber', sort: false, title: '排序'}
                            , {align: 'center', toolbar: '#sysSettingTableDetailBar', title: '操作'}
                        ]],
                    });

                    // 添加广告
                    $('#addAdvert').click(function () {
                        admin.open({
                            type: 1,
                            area: ['1180px', '800px'],
                            offset: '65px',
                            title: '广告添加',
                            content: $('#sysSettingDetailForm').html(),
                            success: function () {
                                form.val('sysSettingDetailForm', data);

                                form.on('submit(settingFormDetailSubmit)', function (d) {
                                    d.field.settingId = data.id
                                    var b =document.getElementById("headerImg").getElementsByTagName("img");
                                    console.log(b[0].currentSrc)
                                    d.field.advertUrl = b[0].currentSrc
                                    // 表单提交事件
                                    admin.req('enterprisecab/setting/admin/sysSettingAdvert/add', d.field, function (res) {
                                        layer.closeAll('loading');
                                        if (res.code == 200) {
                                            layer.msg(res.msg, {icon: 1});
                                            table.reload('sysSettingTable');
                                            layer.closeAll('page');
                                            // 渲染表格
                                            table.reload('sysSettingTable');
                                        } else {
                                            layer.msg(res.msg, {icon: 2});
                                        }
                                    }, 'POST', true);
                                    return false;
                                });
                                form.render("select");
                                //上传头像
                                $('#devicePicBtn').click(uploadImg('devicePicBtn', 'headerImg', 'advertUrl'))
                                $('#deviceVideoBtn').click(uploadImg2('deviceVideoBtn', 'headerVideo', 'advertVideo'))
                            }
                        });
                    })

                    // 表单提交事件
                    form.on('submit(submitSys)', function (d) {

                        d.field.id = data.id
                        admin.req('enterprisecab/cabinet/admin/sysSetting/update', d.field, function (res) {
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                table.reload('sysSettingTable');
                                layer.closeAll('page');
                                // 渲染表格
                                settingList = [];
                                advertList = [];

                                table.reload('sysSettingTable');
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'PUT');
                        return false;
                    });
                    //上传头像
                    $('#btn').click(uploadImg('btn', 'headImg', 'codeUrl'))
                    $('#logoBtn').click(uploadImg('logoBtn', 'logoImg', 'logoUrl'))
                    //显示input内容
                    document.getElementById('email').value=data.email;
                    // $('#headerImg').html('<img src="' + advertListin[0].codeUrl + '" style="height: 35px;" />');
                    document.getElementById('headImg').innerHTML='<img src="'+data.codeUrl+'"style="height: 35px;"/>'
                    document.getElementById('codeUrl').value = data.codeUrl;
                    document.getElementById('logoImg').innerHTML='<img src="'+data.logo+'"style="height: 35px;"/>'
                    document.getElementById('logoUrl').value = data.logo;
                    document.getElementById('mobile').value=data.mobile;
                    document.getElementById('advertName').value=data.advertName;

                }
            });
        }

       function showEditDetailModel(data){
           admin.open({
               type: 1,
               area: ['1180px', '800px'],
               offset: '65px',
               title: '广告修改',
               content: $('#sysSettingDetailForm').html(),
               success: function () {
                   form.val('sysSettingDetailForm', data);
                   admin.req('enterprisecab/cabinet/admin/sysSetting/getSettingById', {id: data.id}, function (res) {
                       advert = res.data;
                       $('#name').val(res.data.name);
                       $('#headerImg').html('<img src="' + res.data.advertUrl + '" style="height: 35px;" />');
                       $('#advertLink').val(res.data.advertLink);
                       $('#remark').val(res.data.remark);
                       $('#sortNumber').val(res.data.sortNumber);
                   }, 'GET', false)
                   form.on('submit(settingFormDetailSubmit)', function (d) {
                       d.field.id = data.id
                       var b =document.getElementById("headerImg").getElementsByTagName("img");
                       console.log(b[0].currentSrc)
                      d.field.advertUrl = b[0].currentSrc
                       // 表单提交事件
                       admin.req('enterprisecab/cabinet/admin/sysSetting/upDate', JSON.stringify(d.field), function (res) {
                           layer.closeAll('loading');
                           if (res.code == 200) {
                               layer.msg(res.msg, {icon: 1});
                               table.reload('sysSettingTable');
                               layer.closeAll('page');
                               // 渲染表格
                               table.reload('sysSettingTable');
                           } else {
                               layer.msg(res.msg, {icon: 2});
                           }
                       }, 'POST', true, 'application/json; charset=utf-8');
                       return false;
                   });
                   form.render("select");
                   //上传头像
                   $('#devicePicBtn').click(uploadImg('devicePicBtn', 'headerImg', 'advertUrl'))
                   $('#deviceVideoBtn').click(uploadImg2('deviceVideoBtn', 'headerVideo', 'advertVideo'))
               }
           });
        }

        // 添加按钮点击事件
        $('#addSetting').click(function () {
            showAddModel();
        });
        // 添加 addSettingForm
        function showAddModel(){
            admin.open({
                type: 1,
                area: ['1390px', '700px'],
                offset: '85px',
                title: '添加',
                content: $('#addSettingForm').html(),
                success: function () {
                    // 添加详情按钮点击事件
                    $('#addAdvertBtn').click(function () {
                        showAddAdvertModel();
                    })
                    //加载代理商列表
                    // admin.reqSync('platform/company/admin/company/list', {limit: 99999}, function (res) {
                    //
                    //     loadSelectHtml(res.data, "请选择企业", "enterpriseId", "name");
                    //     // 第二步 进行数据配对的选择
                    //     // 下拉框回显
                    //     var select = 'dd[lay-value=' + advertin.enterpriseId + ']';
                    //     var changeselect = $('#enterpriseId').siblings("div.layui-form-select").find('dl').find(select).click();
                    //     form.render("select");
                    // }, 'get', false);
                    //上传头像
                    $('#btn').click(uploadImg('addBtn', 'addHeadImg', 'addCodeUrl'))
                    $('#addLogoBtn').click(uploadImg('addLogoBtn', 'addLogoImg', 'addLogoUrl'))
                    form.on('submit(addSetting)', function (d) {
                        console.log(d.field)
                        d.field.id = ids
                        admin.req('enterprisecab/cabinet/admin/sysSetting/update', d.field, function (res) {
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                table.reload('sysSettingTable');
                                layer.closeAll('page');

                                table.reload('sysSettingTable');
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'PUT');
                        return false;
                    });
                    console.log(addAdvertList)
                    var insTb = table.render({
                        elem: '#addSettingTable',
                        // url: config.base + 'enterprisecab/cabinet/admin/startSetting/list',
                        cellMinWidth: 100,
                        data: addAdvertList,
                        cols: [[
                            {type: 'numbers', title: '序号'}
                            , {field: 'name', sort: true, title: '广告名称'}
                            , {field: 'advertUrl', sort: true, title: '广告图片',templet: '#advertPicture'}
                            , {field: 'advertLink', sort: true, title: '广告链接'}
                            ,{field: 'isDeleted', templet: '#isDeletedTable', title: '是否启用', unresize: true}
                            , {field: 'remark', sort: true, title: '备注'}
                            // , {field: 'createTime', sort: true, title: '添加时间'}
                            , {field: 'sortNumber', sort: true, title: '排序'}
                            // , {align: 'center', toolbar: '#sysSettingTableDetailBar', title: '操作'}
                        ]],
                    });
                    form.on('submit(addSettingSubmit)', function (d) {
                        d.field.advert = addAdvertList;
                        for (let i = 0; i <d.field.advert.length ; i++) {
                            if (d.field.advert[i].isDeleted==0){
                                d.field.advert[i].isDeleted = false
                            }else {
                                d.field.advert[i].isDeleted = true
                            }
                        }
                        console.log(d.field)
                        admin.req('enterprisecab/cabinet/admin/startSetting/addSettingList', JSON.stringify(d.field), function (res) {

                            layer.closeAll('loading');
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                table.reload('sysSettingTable');
                                layer.closeAll('page');
                                // 渲染表格
                                settingList = [];
                                advertList = [];

                                table.reload('sysSettingTable');
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'POST',true, 'application/json;charset=utf-8')
                        return false;
                    })

                }
            })
        }

        // 添加详情数据
        function showAddAdvertModel(){
          let  addDetail = admin.open({
                type: 1,
                area: ['1180px', '800px'],
                offset: '65px',
                title: '广告添加',
                content: $('#sysSettingDetailForm').html(),
                success: function () {
                    form.render("select");
                    //上传头像
                    $('#devicePicBtn').click(uploadImg('devicePicBtn', 'headerImg', 'advertUrl'))
                    $('#deviceVideoBtn').click(uploadImg2('deviceVideoBtn', 'headerVideo', 'advertVideo'))
                    form.on('submit(settingFormDetailSubmit)', function (d) {
                        // 将数据存储
                        addAdvertList.push(d.field);
                        layer.close(addDetail);
                        table.reload('addSettingTable', {data: addAdvertList});
                        console.log(addAdvertList)
                        return false;
                    });
                    form.render("select");
                }
            })
        }


        // 上传图片
        function uploadImg(_elem, pathId, inputId) {
            upload.render({
                elem: '#' + _elem
                , url: config.upload_url + 'uploadFile'
                , data: {}
                , accept: 'file'
                , exts: 'jpg|png|RAR|zip|pdf|txt|doc|docx|xls|xlsx|ppt|pptx|mp4|m4v|wmv|flv'
                , headers: {Authorization: 'Bearer ' + config.getToken()}
                , done: function (res) {
                    if (res.code == 200) {
                        layer.msg(res.msg || "上传成功", {icon: 1});
                        let imagUrl = res.data.url;
                        console.log(imagUrl)
                        $('#' + pathId).html('<img src="' + imagUrl + '"/>');
                        $('#' + inputId).val(imagUrl);
                    } else if (res.code == 502) {
                        return location.replace('admin/login.html');
                    } else {
                        layer.msg(res.msg || "上传失败", {icon: 2});
                    }
                }
            });
        }
        // 上传图片
        function uploadImg2(_elem, pathId, inputId) {
            upload.render({
                elem: '#' + _elem
                , url: config.upload_url + 'uploadFile'
                , data: {}
                , accept: 'file'
                , exts: 'jpg|png|RAR|zip|pdf|txt|doc|docx|xls|xlsx|ppt|pptx|mp4|m4v|wmv|flv'
                , headers: {Authorization: 'Bearer ' + config.getToken()}
                , done: function (res) {
                    if (res.code == 200) {
                        layer.msg(res.msg || "上传成功", {icon: 1});
                        let imagUrl = res.data.url;
                        console.log(imagUrl)
                        $('#' + pathId).html(imagUrl);
                        $('#' + inputId).val(imagUrl);
                    } else if (res.code == 502) {
                        return location.replace('admin/login.html');
                    } else {
                        layer.msg(res.msg || "上传失败", {icon: 2});
                    }
                }
            });
        }


        //监听排序
        table.on('sort(sysSettingTable)', function (obj) {
            table.reload('sysSettingTable', {
                initSort: obj
                , where: {
                    sort: obj.field
                    , order: obj.type
                }
            });
        });

        // 搜索
        form.on('submit(formSearch)', function (data) {
            insTb.reload({where: data.field, page: {curr: 1}}, 'data');
        });





        // 删除
        function doDelete(obj) {
            layer.confirm('确定要删除吗？', {
                offset: '65px',
                skin: 'layui-layer-admin'
            }, function (i) {
                layer.close(i);
                layer.load(2);
                admin.req('platform/cabinet/admin/sysSetting/' + obj.data.id, {}, function (res) {
                    layer.closeAll('loading');
                    if (res.code == 200) {
                        layer.msg(res.msg, {icon: 1});
                        obj.del();
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                }, 'DELETE');
            });
        }


        /**
         * 加载地址HTML
         * @param data 下拉菜单数据
         * @param tips select 默认提示
         * @param htmltarget html要插入的位置
         * @param name  下拉框需要显示值的属性
         */
        function loadSelectHtml(data, tips, htmltarget, name) {
            let html = ' <option value>' + tips + '</option>';
            if (!data || data == null) {
                return;
            }
            for (let i = 0; i < data.length; i++) {
                let isFinalCategory = '';
                if (data[i].isFinalCategory != undefined) {
                    isFinalCategory = `isFinal=` + data[i].isFinalCategory;
                }
                html += `<option value='${data[i].id}' ${isFinalCategory}>${data[i][name]}</option>`;
            }
            $("[name='" + htmltarget + "']").html(html);
            form.render();
        }

    });
</script>
<style>
    .allSpan {
        color: red;
    }

</style>